package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysClientVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysClient;
import com.ruoyi.system.service.ISysClientService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库用户管理Controller
 * 
 * @author ruoyi
 * @date 2023-12-10
 */
@Api("仓库用户信息管理")

@RestController
@RequestMapping("/system/client")
public class SysClientController extends BaseController
{
    @Autowired
    private ISysClientService sysClientService;

    /**
     * 查询仓库用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:client:list')")
    @ApiOperation(" 查询仓库用户管理列表")
    @GetMapping("/list")
    public TableDataInfo list(SysClient sysClient)
    {
        startPage();
        List<SysClient> list = sysClientService.selectSysClientList(sysClient);
        return getDataTable(list);
    }

    /**
     * 导出仓库用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:client:export')")
    @ApiOperation(" 导出仓库用户管理列表")
    @Log(title = "仓库用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysClient sysClient)
    {
        List<SysClient> list = sysClientService.selectSysClientList(sysClient);
        ExcelUtil<SysClient> util = new ExcelUtil<SysClient>(SysClient.class);
        util.exportExcel(response, list, "仓库用户管理数据");
    }

    /**
     * 获取仓库用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:client:query')")
    @ApiOperation("获取仓库用户管理详细信息 ")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysClientService.selectSysClientById(id));
    }

    /**
     * 新增仓库用户管理
     */
    @PreAuthorize("@ss.hasPermi('system:client:add')")
    @Log(title = "仓库用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增仓库用户管理 ")
    public AjaxResult add(@RequestBody SysClient sysClient)
    {
        return toAjax(sysClientService.insertSysClient(sysClient));
    }

    /**
     * 修改仓库用户管理
     */
    @PreAuthorize("@ss.hasPermi('system:client:edit')")
    @Log(title = "仓库用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(" 修改仓库用户管理")
    public AjaxResult edit(@RequestBody SysClientVo sysClientVo)
    {
        return toAjax(sysClientService.updateSysClient(sysClientVo));
    }


    /**
     * 修改仓库用户管理
     */
    @PreAuthorize("@ss.hasPermi('system:client:edit')")
    @Log(title = "仓库用户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/bind/{key}")
    @ApiOperation("仓库用户绑定钱包秘钥")
    public AjaxResult addWalletKey( @PathVariable String key)
    {
        return toAjax(sysClientService.sysClientAddWalletKey(key));
    }



    /**
     * 删除仓库用户管理
     */
    @PreAuthorize("@ss.hasPermi('system:client:remove')")
    @Log(title = "仓库用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除仓库用户管理 ")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysClientService.deleteSysClientByIds(ids));
    }
}
